﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using GPS.DAL;
using GPS.MODELS;
using System.Data.SqlClient;
using System.Timers;
using System.Data;
using System.Data.Entity;
using Microsoft.AspNet.Identity;
using GPS.DataAccessLayer;
using GPS.COMMON;
using GPS.GPS_DAL;


namespace GPS.Controllers
{
    public class HomeController : Controller
    {
        private ApplicationDbContext db = new ApplicationDbContext();
        // private GPS.DataAccessLayer.GPSContext _db = new GPS.DataAccessLayer.GPSContext();
        public ActionResult Index()
        {
         //   ApplicationUser curUser = getCurrentUser();
            //count so giay phep het han
            DbContextHelper<GPS_NVContext> _db = Singleton<DbContextHelper<GPS_NVContext>>.Inst;
            var _exists = false;// _db.EntityExists<DDSCANHBAO>(o => o.DSCANHBAO_USER.ToUpper() == User.Identity.Name.ToUpper());
            if (_exists)
            {
                string _maGTVT = this.getCurrentUser().MA_TINHTP;
                ViewBag.Display = "block";
                ViewBag.GPS_CANHBAO_PTs = Singleton<GPS_CanhBaoDAO>.Inst.GPS_CANHBAO_PT(_maGTVT);
                ViewBag.GPS_CANHBAO_CSDTs = Singleton<GPS_CanhBaoDAO>.Inst.GPS_CANHBAO_CSDT(_maGTVT);
                ViewBag.GPS_CANHBAO_GV_DUP_CMTs = Singleton<GPS_CanhBaoDAO>.Inst.GPS_CANHBAO_GV_DUP_CMT();
                ViewBag.GPS_CANHBAO_PT_DUP_BIENSOs = Singleton<GPS_CanhBaoDAO>.Inst.GPS_CANHBAO_PT_DUP_BIENSO();

            }
            else
            {
                ViewBag.Display = "none";
            }

            return View();
        }

        public ApplicationUser getCurrentUser()
        {
            ApplicationDbContext dbUser = new ApplicationDbContext();

            string userId = User.Identity.GetUserId();

            ApplicationUser _currentUser = db.Users.Find(userId);

            return _currentUser;
        }

        public ActionResult Denied()
        {
            return View();
        }


        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}